<template>
	<view class="page">
		<view class="tip">
			<text style="color: red; margin-top: 5rpx; margin-right: 8rpx;font-size: 28rpx;">*</text><text>请如实上传您的<text
					style="color: red;">收入流水PDF文件</text>，否则会影响您的评估结果。<text style="color: red;">注意：系统会从（微信聊天记录）或者（微信文件助手）内调用 PDF 文件，避免浪费您的时间请您提前准备。</text></text>
		</view>
		<view class="newuploaad" style="background-color: #fff;">
			<view class="upload" style="display: flex;align-items: center;flex-wrap: wrap;justify-content: flex-start;">
				<view class="shilitu zidingyi" style="margin-right: 15rpx;" v-for="(items,index) in ImageData"
					:key="items.id" >
					<image :src="items.path" style="width: 100%;height: 100%;" v-if="items.type"
						@click="danYuLan(index)">
					</image>
					<view class="" v-else @click="yulan(index)">
						<!-- {{flieName}} -->
						文件({{items.fileExt}})
					</view>
					<view class="cha" @click="del(index)">
						<u-icon name="close" style="font-size: 8rpx;margin-left: 3rpx;" color="#fff" size="16rpx"></u-icon>
					</view>
					<view class="duigou">
						<view class="dui">
							<u-icon name="checkmark" style="font-size: 8rpx;margin-left: 3rpx;" color="#fff" size="16rpx" class="dui"></u-icon>
						</view>
					</view>
				</view>
				<u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic"
					@clickPreview="clickPreviewimg" :previewImage="false" upload-text="收入流水" limitType="['pdf']"
					name="1" multiple :maxCount="10" :capture="{ audio: true,video: true }" :methods="['capture']"
					accept="all" style="width: 145rpx;height: 145rpx;">
				</u-upload>
				<view class="shilitu" @click="showImg(liushuishili)">
					示例图
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				flieName:'',
				ImageData: [],
				fileList1: [
				],
				action: this.$baseUrl + "/dev/file/vxUploadDynamicReturnUrl", //文件上传接口
				liushuishili: ['https://admintestapi.wemo.group//dev/file/download?id=1665973577936154626']
			}
		},
		created() {},
		methods: {
			// 查看文件
			yulan(index) {
				this.$daoChu(this.ImageData[index].path)
			},
			// 示例图预览
			showImg(path) {
				console.log(path);
				uni.previewImage({
					urls: [...path]
				})
			},
			danYuLan(index) {
				console.log(this.ImageData, 'this.ImageData');
				uni.previewImage({
					urls: [this.ImageData[index].path]
				})
			},
			del(index) {
				this.ImageData.splice(index, 1);
			},
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				this.flieName = event.file[0].name
				console.log(event,'11111111111111');
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					let a = 0;
					if (event.name == 1) {
						a = 1;
					}
					if (event.name == 2) {
						a = 2;
					}
					const result = await this.uploadFilePromise(lists[i].url, a)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url, type) {
				uni.showLoading({
					mask: true
				})
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: this.action, // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							user: 'test'
						},
						success: (res) => {
							console.log(url, type);
							var fileExt = url.split('.').pop(); // 'jpg'
							const imageExtensions = ['jpg', 'jpeg', 'png', 'gif'];
							var fig = imageExtensions.includes(fileExt)
							console.log(fig, 'fig');
							uni.hideLoading()
							this.ImageData.push({
								path: JSON.parse(res.data).data,
								type: fig,
								flieName:this.flieName,
								fileExt: fileExt
							})
							console.log(this.ImageData, '上传成功后返回的路径');
							return resolve(JSON.parse(res.data).data)
						},
						error: () => {
							uni.hideLoading()
						}
					});
				})
			},
			
		}
	}
</script>

<style scoped>
	.page {
		padding: 0;
		margin: 0;
		overflow-y: hidden;
		width: 100%;
		/* height: 100vh; */
		background-color: #fff;
		/* padding: 0 30rpx 102rpx; */
		box-sizing: border-box;
		/* background-color: red; */
	}

	.tip {
		display: flex;
		align-items: flex-start;
		font-size: 24rpx;
		font-family: 'PingFang SC-Regular, PingFang SC';
		font-weight: 400;
		color: #B1B1B1;
		margin-top: 24rpx;
	}

	.uploaad {
		/* width: 690rpx; */
		/* height: 297rpx; */
		background: #F9F9F9;
		/* border-radius: 15rpx 15rpx 15rpx 15rpx; */
		margin-top: 32rpx;
	}

	.uploaad {
		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;
	}

	.icon {
		font-size: 108rpx;
		font-family: 'Rubik-Regular, Rubik';
		font-weight: 400;
		color: #C4C4C4;
	}

	.items {
		display: flex;
		justify-content: space-between;
		align-items: center;
		/* padding: 0 31rpx; */
		box-sizing: border-box;
		width: 100%;
		height: 97rpx;
		border-bottom: 2rpx solid #F4F4FA;
		/* background-color: aqua; */
	}

	.items_left {
		font-size: 24rpx;
		font-family: 'PingFang SC-Regular, PingFang SC';
		font-weight: 400;
		color: #1A1824;

	}

	.fenGe {
		/* width: 690rpx; */
		height: 15rpx;
		background: #F4F4FA;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
	}

	.tishi {
		height: 66rpx;
		font-size: 24rpx;
		font-family: 'PingFang SC-Regular, PingFang SC';
		font-weight: 400;
		color: #B1B1B1;
	}

	.xie_yi {
		display: flex;
		justify-content: flex-start;
		align-items: flex-start;
		height: 66rpx;
		font-size: 24rpx;
		font-family: 'PingFang SC-Regular, PingFang SC';
		font-weight: 400;
		color: #B1B1B1;
		margin: 34rpx 0 76rpx;
	}

	.items_rght_tips {
		font-size: 28rpx;
		font-family: 'PingFang SC-Regular, PingFang SC';
		font-weight: 400;
		color: #9D9D9D;
	}

	.but {
		position: fixed;
		bottom: 196rpx;
	}

	.newuploaad {
		display: flex;
		align-items: flex-start;
		justify-content: flex-start;
		flex-wrap: wrap;
		margin-top: 32rpx;
	}

	.items {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 0 31rpx;
		box-sizing: border-box;
		width: 100%;
		height: 97rpx;
		border-bottom: 2rpx solid #F4F4FA;
		/* background-color: aqua; */
	}

	.items_left {
		font-size: 28rpx;
		font-family: 'PingFang SC-Regular, PingFang SC';
		font-weight: 400;
		color: #1A1824;

	}

	.shilitu {
		text-align: center;
		line-height: 145rpx;
		width: 145rpx;
		height: 145rpx;
		font-size: 24rpx;
		background-color: #f4f5f7;
		margin-bottom: 16rpx;
	}

	.zidingyi {
		position: relative;
	}

	.cha {
		position: absolute;
		width: 24rpx;
		height: 24rpx;
		top: 0rpx;
		right: 0rpx;
		background-color: brown;
		border-bottom-left-radius: 24rpx;
		background-color: red;
		line-height: 15rpx;
		background-color: #373737;
		color: #fff;
		padding-left: 8rpx;
		padding-top: 3rpx;
		box-sizing: border-box;
	}

	.duigou {
		position: absolute;
		bottom: -21rpx;
		right: -21rpx;
		width: 0;
		height: 0;
		border-top: 21rpx solid #5ac725;
		border-right: 21rpx solid transparent;
		border-bottom: 21rpx solid transparent;
		border-left: 21rpx solid transparent;
		transform: rotate(-45deg);
	}
	.dui {
		position: absolute;
		z-index: 99;
		bottom: 6rpx;
		right: -4rpx;
		transform: rotate(45deg);
	}
</style>